package tzjz.web.controller;

import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import tzjz.web.domain.PingLun;
import tzjz.web.service.IPingLunService;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * 首页 控制器
 * @author coffee
 */
@Controller
public class IndexController {

    @Autowired
    private IPingLunService iPingLunService;

    /**
     * 首页
     */
    @RequestMapping(value = "index")
    public String index(Model model) {
        List<PingLun> list = iPingLunService.selectList();
        model.addAttribute("pingLunList",list);
        return "index/index";
    }

    /**
     * 推荐
     *
     */
    @RequestMapping(value = "translate")
    public String  translate( Model model) {

        return "translate";
    }

    /**
     * 评论
     *
     */
    @RequestMapping(value = "pingLun")
    public String  pingLun( Model model) {
        List<PingLun> list = iPingLunService.selectList();
        model.addAttribute("pingLunList",list);
        return "pingLun";
    }

    /**
     * 新增评论
     *
     */
    @RequestMapping(value = "addPingLun")
    public String  addPingLun( Model model,PingLun pingLun) {
        String content = pingLun.getContent();
        pingLun.setCreatedOn(new Date());
        iPingLunService.insertPingLun(pingLun);
        List<PingLun> list = iPingLunService.selectList();
        model.addAttribute("pingLunList",list);
        return "pingLun";
    }
}